package com.powernobug.service.impl;

import com.powernobug.bean.model.MarketAdmin;
import com.powernobug.bean.vo.data.LoginInfoData;
import com.powernobug.mapper.MarketAdminMapper;
import com.powernobug.service.AdminAuthService;
import com.powernobug.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-20
 * @Description:
 */
public class AdminAuthServiceImpl implements AdminAuthService {
    private static SqlSession tempSession;

    @Override
    public MarketAdmin login(String username){
        tempSession = MyBatisUtil.getSqlSession();
        MarketAdmin marketAdmin = null;
        marketAdmin = tempSession.getMapper(MarketAdminMapper.class).selectByUserName(username);
        MyBatisUtil.releaseSqlSession(tempSession);
        return marketAdmin;
    }

    @Override
    public LoginInfoData info(Integer adminId) {
        tempSession = MyBatisUtil.getSqlSession();
        MarketAdmin marketAdmin = null;
        marketAdmin = tempSession.getMapper(MarketAdminMapper.class).selectByPrimaryKey(adminId);
        MyBatisUtil.releaseSqlSession(tempSession);

        return LoginInfoData.builder()
                .roles(List.of("超级管理员"))
                .name(marketAdmin.getUsername())
                .perms(List.of("*"))
                .avatar(marketAdmin.getAvatar())
                .build();
    }
}
